import { Injectable } from '@nestjs/common';
import { CreateGroupDto } from './dto/create-group.dto';
import { UpdateGroupDto } from './dto/update-group.dto';
import { User } from '@prisma/client';
import { PrismaService } from 'src/prisma.service';
import { TRes } from 'src/common/base';

@Injectable()
export class GroupService {

  constructor(private prisma: PrismaService) { }

  async getGroupUsers(groupId: string): Promise<TRes<User[]>> {
    try {
      const userIdList = await this.prisma.groupMap.findMany({
        where: { groupId: groupId },
        select: { userId: true }
      })
      const userArr = []
      for (const user of userIdList) {
        const data = await this.prisma.user.findUnique({
          where: {
            userId: user.userId
          }
        })
        userArr.push(data)
      }
      return {
        data: userArr,
      }
    } catch (error) {
      return {
        msg: error,
        data: null,
        sql: true // 执行sql失败
      }
    }
  }

}
